import pandas as pd
from pandas import DataFrame

def pandas_data_frame_statistics():
  # 统计函数
  excel_file_path = '/Users/longhairen/Documents/pycharm/learn-python/data/students_scores.xlsx'
  score = DataFrame(pd.read_excel(excel_file_path))
  print("score原始数据如下:\n", score)
  print("\ncount(axis0)如下:\n", score.count(axis=0))
  print("\ncount(axis1)如下:\n", score.count(axis=1))
  print("\ndescribe如下:\n", score.describe())
  print("\nmin如下:\n", score.min())
  print("\nmax如下:\n", score.max())
  print("\nsum如下:\n", score.sum())
  # 使用 numeric_only=True 参数只对数值列进行计算
  print("\nmean如下:\n", score.mean(numeric_only=True))



if __name__ == '__main__':
  pandas_data_frame_statistics()

def pandas_data_frame():
  excel_file_path = '/Users/longhairen/Documents/pycharm/learn-python/data/students_scores.xlsx'
  score = DataFrame(pd.read_excel(excel_file_path))
  print(score)

  drop_score = score
  drop_score = drop_score.drop(columns=['语文'])
  drop_score = drop_score.drop(index=0)
  print(drop_score)
  excel_file_path = '/Users/longhairen/Documents/pycharm/learn-python/data/students_scores_drop.xlsx'
  drop_score.to_excel(excel_file_path, index=False)

  score.rename(columns={'语文': 'Chinese', '英语': 'English'}, inplace=True)
  # score.to_excel('输出.xlsx')
  print(score)
  # 将列的数据类型转换为字符串
  score['语文'].astype('str')

  # 删除左右两边空格
  # df2['Chinese'] = df2['Chinese'].map(str.strip)
  # 删除左边空格
  # df2['Chinese'] = df2['Chinese'].map(str.lstrip)
  # 删除右边空格
  # df2['Chinese'] = df2['Chinese'].map(str.rstrip)
  # 删除字符
  # df2['Chinese'] = df2['Chinese'].str.strip('$')

  # 全部大写
  # df2.columns = df2.columns.str.upper()
  # 全部小写
  # df2.columns = df2.columns.str.lower()
  # 首字母大写
  # df2.columns = df2.columns.str.title()
  # 删除空格
  # df.isnull()



def apply_function():
  def double_df(x):
    return 2 * x

  score = DataFrame(pd.read_excel('成绩表.xlsx'))
  score['语文'] = score['语文'].apply(double_df)
  print(score)

